<template>
	<div>
		<Button type="primary" @click="onAdd">添加</Button>
		<Input v-model="filter.name">
	        <!-- <Select v-model="select3" slot="prepend" style="width: 80px">
	            <Option value="day">日活</Option>
	            <Option value="month">月活</Option>
	        </Select> -->
	        <Button slot="append" icon="ios-search" @click="onSearch"></Button>
	    </Input>
	    <Button type="error" @click="onDeletes">删除多条记录</Button>

	    <Table border :columns="columns" :data="filter.list" @on-selection-change="onSelectionChange"></Table>
	    <Page :total="filter.total" size="small"
	     show-total show-elevator show-sizer
	     @on-change="onChange"
	     @on-page-size-change="onPageSizeChange"></Page>

	    <Modal
	        v-model="modal"
	        title="数据操作"
	    >
	        <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">

		        <FormItem label="姓名" prop="name">
		            <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
		        </FormItem>
		        <FormItem label="密码" prop="password">
		            <Input v-model="formValidate.password" placeholder="请输入密码"></Input>
		        </FormItem>
		        <!-- <FormItem label="城市" prop="city">
		            <Select v-model="formValidate.city" placeholder="请选择所在地">
		                <Option value="beijing">北京市</Option>
		                <Option value="shanghai">上海市</Option>
		                <Option value="shenzhen">深圳市</Option>
		            </Select>
		        </FormItem>
		        <FormItem label="选择日期">
		            <Row>
		                <Col span="11">
		                    <FormItem prop="date">
		                        <DatePicker type="date" placeholder="选择日期" v-model="formValidate.date"></DatePicker>
		                    </FormItem>
		                </Col>
		                <Col span="2" style="text-align: center">-</Col>
		                <Col span="11">
		                    <FormItem prop="time">
		                        <TimePicker type="time" placeholder="选择时间" v-model="formValidate.time"></TimePicker>
		                    </FormItem>
		                </Col>
		            </Row>
		        </FormItem>
		        <FormItem label="性别" prop="gender">
		            <RadioGroup v-model="formValidate.gender">
		                <Radio label="male">男</Radio>
		                <Radio label="female">女</Radio>
		            </RadioGroup>
		        </FormItem>
		        <FormItem label="爱好" prop="interest">
		            <CheckboxGroup v-model="formValidate.interest">
		                <Checkbox label="吃饭"></Checkbox>
		                <Checkbox label="睡觉"></Checkbox>
		                <Checkbox label="跑步"></Checkbox>
		                <Checkbox label="看电影"></Checkbox>
		            </CheckboxGroup>
		        </FormItem>
		        <FormItem label="介绍" prop="desc">
		            <Input v-model="formValidate.desc" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入..."></Input>
		        </FormItem>-->
		        <FormItem>
		            <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
		            <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
		        </FormItem> 
		    </Form>
	    </Modal>

	</div>
</template>
<script>
import base from '../.././common/base'

    export default {
        mixins:[base],
        data () {
            return {
                module:'users',

            	formValidate: {
                    name: '',
                    password: ''
                    // city: '',
                    // gender: '',
                    // interest: [],
                    // date: '',
                    // time: '',
                    // desc: ''
                },
                ruleValidate: {
                    name: [
                        { required: true, message: '姓名不能为空', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '密码不能为空', trigger: 'blur' },
                    ]
                    // city: [
                    //     { required: true, message: '请选择城市', trigger: 'change' }
                    // ],
                    // gender: [
                    //     { required: true, message: '请选择性别', trigger: 'change' }
                    // ],
                    // interest: [
                    //     { required: true, type: 'array', min: 1, message: '至少选择一个爱好', trigger: 'change' },
                    //     { type: 'array', max: 2, message: '最多选择两个爱好', trigger: 'change' }
                    // ],
                    // date: [
                    //     { required: true, type: 'date', message: '请选择日期', trigger: 'change' }
                    // ],
                    // time: [
                    //     { required: true, type: 'date', message: '请选择时间', trigger: 'change' }
                    // ],
                    // desc: [
                    //     { required: true, message: '请输入个人介绍', trigger: 'blur' },
                    //     { type: 'string', min: 20, message: '介绍不能少于20字', trigger: 'blur' }
                    // ]
                },

                columns: [
                	 {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'ID',
                        key: '_id',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row._id)
                            ]);
                        }
                    },
                    {
                        title: '账户',
                        key: 'name'
                    },
                    {
                        title: '密码',
                        key: 'password'
                    },
                    {
                        title: '增删改查',
                        key: 'data',
                        width: 240,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                            	h('Button', {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.onAdd()
                                        }
                                    }
                                }, '添加'),
                                h('Button', {
                                    props: {
                                        type: 'warning',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.modify(params.index)
                                        }
                                    }
                                }, '查看'),
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.row)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                        	// console.log(params.row._id)
                                        	
                                            this.remove(params.row._id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ]
            }
        }
    }
</script>